import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Downloade from '../views/Download.vue'
import User from '../views/User.vue'
 // 懒加载方式
const news = () => import ('../components/HomeNews.vue')
const Profile = () => import('../views/Profile.vue')


Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/Home',
    name: 'Home',
    meta: {
      title: "主页"
    },
    component: Home,
    children: [
      {
        path: '/',
        redirect:'news'
      },
      {
        path: 'news',
        component: news
      },
    ]
  },
  {
    path: '/about',
    name: 'About',
    meta: {
      title: "关于"
    },
    // 懒加载方式
    component: () => import('../views/About.vue')
  },
  {
    path: '/Download',
    name: 'Download',
    meta: {
      title: "下载"
    },
    component: Downloade
  },
  {
    path: '/User/:UserID',
    name: 'User',
    component: User
  },
  {
    path: '/Profile',
    name: 'Profile',
    meta: {
      title: "档案"
    },
    component: Profile
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => { 
  //从form跳转到to
  //document.title=to.name
  document.title=to.matched[0].meta.title
  next()
})

export default router
